package com.ohuang.apkMerge

import java.io.File

/**
 * 复制并合并文件夹内所有文件
 * targetRootPath为拷贝到的目录
 */
fun copyAndMergePathFile(sourceRootPath: String, targetRootPath: String, path: String = "") {
    var targetFile = File(targetRootPath + path)
    var sourceRootFile = File(sourceRootPath + path)
    if (!targetFile.exists()) {
        targetFile.mkdirs()
    }
    sourceRootFile.listFiles()?.forEach {
        if (it.isDirectory) {
            var newPath = path + "/${it.name}"
            copyAndMergePathFile(sourceRootPath, targetRootPath, newPath)
        } else {
            mergeFile(it.absolutePath, targetRootPath + path + "/" + it.name)
        }
    }
}

fun mergeFile(sourcePath: String, targetPath: String) {
    var file = File(sourcePath)
    if (file.exists()) {
        var file1 = File(targetPath)
        file1.appendBytes(file.readBytes())
    }

}